#!/bin/bash

sudo apt-get -y install git wget zsh

if [ ! -d ~/.oh-my-zsh -o ! -f ~/.zshrc ]; then
    # sh -c "$(wget https://gitee.com/jiejieTop/ohmyzsh/raw/master/tools/install.sh -O -)"
    git clone https://gitee.com/jiejieTop/ohmyzsh.git ~/.oh-my-zsh
    cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc

    git clone https://gitee.com/jiejieTop/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

    git clone https://gitee.com/jiejieTop/zsh-autosuggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

    git clone https://gitee.com/jiejieTop/git-open.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/git-open

    sed -i 's/plugins=(git)/plugins=(z git sudo extract vi-mode git-open safe-paste command-not-found colored-man-pages zsh-syntax-highlighting vscode zsh-autosuggestions)/g' ~/.zshrc
    sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' ~/.zshrc
    sed -i 's/# DISABLE_AUTO_TITLE="true"/DISABLE_AUTO_TITLE="true"/g' ~/.zshrc

    # 如果 ~/.zshrc 中没有 ZSH_DISABLE_COMPFIX="true" 则添加
    if [ -f "~/.zshrc" ]; then
        has_opencv=$(grep -c 'ZSH_DISABLE_COMPFIX="true"' ~/.zshrc)
        if [  "$has_opencv" == "0" ];then
            # 在 ~/.zshrc 的第1行添加 ZSH_DISABLE_COMPFIX="true"
            sed -i '1i ZSH_DISABLE_COMPFIX="true"' ~/.zshrc
        fi
    fi
fi

# 设置默认 shell 为 zsh
chsh -s $(which zsh)
